package com.ouc.eddyAlgorithm.service.impl;

import com.ouc.common.entity.NcData;
import com.ouc.common.ncRead.NcDao;
import com.ouc.eddyAlgorithm.service.TmEddyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ucar.ma2.InvalidRangeException;
import ucar.nc2.NetcdfFile;

import java.io.IOException;
import java.util.Map;

@Service
public class TmEddyServiceImpl implements TmEddyService {

  @Autowired
  NcDao ncDao;

  private double[][] H = {
      {0, 0, 1, 1, 1, 0, 0},
      {0, 1, 1, 1, 1, 1, 0},
      {1, 1, 1, 1, 1, 1, 1},
      {1, 1, 1, 0, 1, 1, 1},
      {1, 1, 1, 1, 1, 1, 1},
      {0, 1, 1, 1, 1, 1, 0},
      {0, 0, 1, 1, 1, 0, 0}};
  private double[][] A = {
      {-2.35619449, -2.55359005, -2.819842099, 3.141592654, 2.819842099, 2.55359005, 2.35619449},
      {-2.15879893, -2.35619449, -2.677945045, 3.141592654, 2.677945045, 2.35619449, 2.15879893},
      {-1.892546881, -2.034443936, -2.35619449, 3.141592654, 2.35619449, 2.034443936, 1.892546881},
      {-1.570796327, -1.570796327, -1.570796327, 0, 1.570796327, 1.570796327, 1.570796327},
      {-1.249045772, -1.107148718, -0.785398163, 0, 0.785398163, 1.107148718, 1.249045772},
      {-0.982793723, -0.785398163, -0.463647609, 0, 0.463647609, 0.785398163, 0.982793723},
      {-0.785398163, -0.588002604, -0.321750554, 0, 0.321750554, 0.588002604, 0.785398163}};



  @Override
  public int tmEddyCenter(String ncFileName, Integer level, Float startLat, Float startLon, Float endLat, Float endLon, Float target) throws IOException, InvalidRangeException {
    try(NetcdfFile ncFile = NetcdfFile.open(ncFileName)){
      Map<String, NcData> uData = ncDao.getNcDataOfLimitFromVariable(ncFile, "u", new Float[]{startLon, endLon}, new Float[]{startLat, endLat}, level);
      float[][] data2D = uData.get(ncDao.getVariable(ncFile, "u").getShortName()).getData2D();
      float[] lonarr = uData.get(ncDao.getVariable(ncFile,"lon").getShortName()).getData1D();

    }catch (Exception e){
      return 2;
    }

    return 1;

  }

}
